package kr.hkit.powerjava.chapter21;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class FileError {

	private int[] list;
	private static final int SIZE = 10;

	public FileError() throws IOException, ArrayIndexOutOfBoundsException {
		list = new int[SIZE];
		for (int i = 0; i < SIZE; i++) {
			list[i] = i;
		}
		writeList();
	}

	public void writeList() throws IOException, ArrayIndexOutOfBoundsException {
		PrintWriter out = null;

		out = new PrintWriter(new FileWriter("outfile.txt"));
		for (int i = 0; i < SIZE; i++) {
			out.println("배열 원소 " + i + " = " + list[i]);
		}

		if (out != null) {
			out.close();
		}
	}

	public static void main(String[] args) {
		try {
			new FileError();
		} catch (ArrayIndexOutOfBoundsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
